package com.langfeiyes.pattern.flyweight;

import java.util.HashMap;
import java.util.Map;


/**
 * 享元工具类
 */
public class FlyweightFactory {
    //享元池
    private Map<String, IFlyWeight> fsmap = new HashMap<>();
    //获取享元，如果有获取，如果没有添加
    public IFlyWeight getFlyweight(String key){
        if(!fsmap.containsKey(key)){
            fsmap.put(key, new ConcreteFlyWeight(key));
        }
        return fsmap.get(key);
    }
}
